package com.ag.admin.web.tags;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.ag.admin.service.IAuthorizeService;
import com.ag.admin.utils.UserUtil;
import com.ag.common.EventUtil;
import com.ag.work2.service.IReportTagService;
import com.ag.zhh.service.EventStatusService;

/**
 * 事件状态标签，用在：我的事件->指挥调度，我的事件->办结报告，当事件状态达到一定级别时才显示
 * 
 * @author Administrator
 * 
 */
public class EventStateTag extends TagSupport implements
		ApplicationContextAware {
	private static final long serialVersionUID = -5082619765870671777L;

	private static ApplicationContext context;// 声明一个静态变量保存

	private IAuthorizeService authorizeService;

	private IReportTagService reportTagService;

	private String permission;

	@Override
	public int doStartTag() throws JspException {
		authorizeService = (IAuthorizeService) context
				.getBean("AuthorizeServiceImpl");
		reportTagService = (IReportTagService) context
				.getBean("LZMReportTagServiceImpl");
		HttpSession session = pageContext.getSession();
		/**
		 * 先判断用户角色，在判断当前事件状态，如果
		 */
		// 事件接报
//		if (EventStatusService.EVENT_STATUS_SJJB.equals(reportTagService
//				.findCurrentEventStatus((String) session
//						.getAttribute(EventUtil.PROCESSING_EVENT_ID)))
//				|| EventStatusService.EVENT_STATUS_SJSHL// 事件受理
//						.equals(reportTagService
//								.findCurrentEventStatus((String) session
//										.getAttribute(EventUtil.PROCESSING_EVENT_ID)))
//				|| EventStatusService.EVENT_STATUS_YJCHP_FINISH// 一级呈批完成
//						.equals(reportTagService
//								.findCurrentEventStatus((String) session
//										.getAttribute(EventUtil.PROCESSING_EVENT_ID)))
//				|| EventStatusService.EVENT_STATUS_ERJCHP_FINISH// 二级呈批完成
//						.equals(reportTagService
//								.findCurrentEventStatus((String) session
//										.getAttribute(EventUtil.PROCESSING_EVENT_ID)))
//				|| EventStatusService.EVENT_STATUS_SJCHP_FINISH// 三级呈批完成
//						.equals(reportTagService
//								.findCurrentEventStatus((String) session
//										.getAttribute(EventUtil.PROCESSING_EVENT_ID)))) {
//			if (!authorizeService.checkRoleGen(session,
//					UserUtil.EMERGENCY_MANAGEMENT)) {
//				if (authorizeService.checkSubmit4Tag(session,(String) session
//							.getAttribute(EventUtil.PROCESSING_EVENT_ID))) {
//					return EVAL_BODY_INCLUDE;
//				}				
//			}
//		}
		if (EventStatusService.EVENT_STATUS_SJCHZH_FINISH.equals(reportTagService
				.findCurrentEventStatus((String) session
				.getAttribute(EventUtil.PROCESSING_EVENT_ID)))) {
			if (authorizeService.checkRoleGen(session,
					UserUtil.VICE_COMMANDER)) {
				return EVAL_BODY_INCLUDE;
			}			
		}
		return SKIP_BODY;
	}

	@Override
	public void setApplicationContext(ApplicationContext contex)
			throws BeansException {
		this.context = contex;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public static ApplicationContext getContext() {
		return context;
	}
}
